<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 *员工管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$tabs=array(
	array('op'=>'list','title'=>'费用列表'),
);
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'gamename'=>$this->plugin_name);
	if(!empty($_RQ['ptitle'])){
		$pids=pdo_getall('jy_merch_game_item',array('uniacid'=>$_SESSION['uniacid'],'title like %'=>$_RQ['ptitle'].'%'),'id','id');
		$params['pid']=array_keys($pids);
		$return['params']['ptitle']=$_RQ['ptitle'];
	}
	if(!empty($_RQ['merchname'])){
		$mid=pdo_getcolumn('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'merchname like %'=>$_RQ['merchname'].'%'),'mid');
		$params['mid']=$mid;
		$return['params']['mid']=$mid;
	}
	if(isset($_RQ['type'])) {
		$params['type']=intval($_RQ['type']);
		$return['params']['type']=intval($_RQ['type']);
	}
	if(isset($_RQ['status'])) {
		$params['status']=intval($_RQ['status']);
		$return['params']['status']=intval($_RQ['status']);
	}
	$pindex = max(1, intval($_RQ['page']));
	$psize = 10;
	$total='';
	$list=pdo_getslice('jy_merch_game_order',$params,array($pindex,$psize),$total,$fields,'','id desc');
	if($list){
		foreach($list as &$item){
			$pitem=pdo_get('jy_merch_game_item',array('uniacid'=>$_SESSION['uniacid'],'id'=>$item['pid']));
			$merch=pdo_get('jy_merch_user',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$pitem['mid']));
			$item['ptitle']=$pitem['title'];
			$item['merchname']=$merch['title'];
			$item['merchlogo']=$merch['logo'];
			$item['member']=cfc('core')->member_show($item['mid']);
		}
	}
	$return['list']=$list;
	$totalpage=ceil($total/$psize);
	$totalpage=intval($totalpage);
	$return['totalpage'] =$totalpage;
	$return['params']['page'] =$pindex;
	$htmls=array(
		'type'=>'list',
		'tabs'=>$tabs,
		'list'=>array('data'=>'list','tip'=>'发布商家同意退款后，才能打款！','edit'=>false,'list'=>array(
			array('name'=>'ordersn','title'=>'订单编号','type'=>'string'),
			array('name'=>'ptitle','title'=>'帖子名称','type'=>'string'),
			array('name'=>'merchname','title'=>'发布商家','type'=>'string'),
			array('name'=>'fee','title'=>'金额','type'=>'string'),
			array('name'=>'member','title'=>'接龙人','type'=>'member'),
			array('name'=>'ispay','title'=>'支付?','type'=>'radio','options'=>'ispay'),
			array('name'=>'status','title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'createtime','title'=>'时间','type'=>'time'),
		),'action'=>array(
			array('op'=>'pay','title'=>'确认退款','type'=>'modal','show'=>array('status'=>6)),
		)),
		'search'=>array(
			array('name'=>'status','width'=>15,'title'=>'状态','type'=>'radio','options'=>'status'),
			array('name'=>'ptitle','width'=>15,'title'=>'帖子名称','type'=>'string'),
			array('name'=>'merchname','width'=>15,'title'=>'发布商家','type'=>'string'),
		)
	);
	$return['ispay']=array('0'=>'待支付','1'=>'已支付','2'=>'支付失败');
	$return['status']=$this->fee_status;
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='pay'){
	if($_RQ['postdata']){
		$post=get_postdata();
		$id=intval($post['id']);
		$this->model('model')->refund_pay($id);
		exi('退款成功！','','list');
	}
	$id=intval($_RQ['id']);
	$item=pdo_get('jy_merch_game_order',array('id'=>$id));
	if(!$item){
		exi('指定退款申请不存在~','error');
	}
	$item['paytype']=get_pay_types()[$item['paytype']];	
	$return['item']=$item;
	$return['htmls']=array(
		'type'=>'edit',
		'edit'=>array(
			array('type'=>'tip','title'=>'【温馨提示】：所有退款将原路返回！'),
			array('type'=>'copy','name'=>'paytype','title'=>'退款类型'),
			array('type'=>'copy','name'=>'fee','title'=>'退款金额'),
			array('type'=>'copy','name'=>'tuidesc','title'=>'退款理由'),
		),
	);
	exi($return);
}
if($_RQ['op']=='del'){
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
	}else{
		$del=array();
	}
	if($_RQ['id']){
		$del[]=$_RQ['id'];
	}
	foreach($del as $id){
		$id=intval($id);
		if($id){
			pdo_delete('jy_merch_game_order',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
		}
	}
	exi('删除成功！');
}
